﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineMovieTicket.Services.IServices;
using OnlineMovieTicket.Services.Services;
using OnlineMovieTicket.Model;

namespace OnlineMovieTicket.WebForms.BuyTicket
{
    public partial class MakePurchase : System.Web.UI.Page
    {
        ITransactionService transactionService = new TransactionService();

        protected void Page_Load(object sender, EventArgs e)
        {
            int movieAssignmentId = Int32.Parse(Request.Params.Get("movieAssignId"));
            int transactionID = Int32.Parse(Request.Params.Get("transactionID"));

            TransactionDetail movieDetail = transactionService.getTransactionDetail(transactionID);
            this.movieName.Text = movieDetail.movieName;
            this.time.Text = movieDetail.ShowDateTime.TimeOfDay.ToString();
            this.amount.Text = movieDetail.Amount.ToString();

            String seatNum = "";

            foreach (String seat in movieDetail.SeatNum)
            {
                seatNum += seat + ",";
            }

            this.seatNum.Text = seatNum.Substring(0, seatNum.Length - 1);

            this.transactionID.Value = transactionID.ToString();
        }

        protected void paymentBtn_Click(object sender, EventArgs e)
        {
            Model.TransactionDetail payment = new TransactionDetail();

            payment.PhoneNo = this.phoneNo.Text;
            payment.NRIC = this.nric.Text;
            payment.Status = "A";
            payment.Email = this.email.Text;
            payment.CustomerName = this.name.Text;
            payment.TransactionID = Int32.Parse(this.transactionID.Value);
            transactionService.bookMovieTicket(payment);
            Response.Redirect("PurchaseDetail.aspx?creditNum=" + creditNum.Text + "&nric=" + nric.Text + "&amount=" + amount.Text + "&seatNum=" + seatNum.Text + "&email=" + email.Text+"&phone="+phoneNo.Text);
        }

        
    }
}